#!/bin/bash
# Last modified Wed May 15 08:26:54 2013 on havoc
# Update count: 130
#
# release - release script for python projects
# Copyright (C) 2008-2013  Albert Thuswaldner
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

if [ $# -lt 1 ]; then 
    cat <<HELP
release  tag, build and register a new release of the project. 
  
USAGE: ./release versionnumber 

HELP
    exit 0
fi  
# Set variables       
VER=$1

# Get repository info
PROJ="pyhdf5io"
REPO="https://code.googlecode.com/p/"$PROJ$"/"
TAGNAME=$PROJ"-"${VER//./-}
MESSAGE="Tagging version "$VER
INITFILE="hdf5io/__init__.py"

# Ask user to confirm
echo Tagging....
echo $TAGNAME 

while true; do
  read -p "Confirm (y/n)? " 
  case $REPLY in
      y* | Y* ) 
	  # Update files with new version number
	  sed "s/__version__\ =\ [^ ]*/__version__\ =\ '$VER'/g" \
	      $INITFILE > temp 
	  mv -f temp $INITFILE

	  git ci -m "Uped version" $INITFILE 
	  
	  # Tagging version
	  git tag -a $TAGNAME -m "$MESSAGE"

	  git push $REPO

	  # bulid source distribution and register 
	  python3 ./setup.py sdist
	  python3 ./setup.py register
	  python3 ./googlecode_upload_py3k.py -s "version "$VER -p $PROJ \
	      dist/$PROJ-$VER.tar.gz
 
	  break;
	  ;; 
      [nN]* )   command ; break 
	  ;;
      q* ) exit 
	  ;;
      * ) echo "Enter yes or no" 
	  ;;
  esac
done
